import { IBaseTimer } from "./IBaseTimer";
import { TimerType } from "./TimerType";
type int = number;
//class BaseTimer

    export  class BaseTimer implements IBaseTimer
    {
        constructor(arg1: number, arg2: number)
        {
            
            var loc1;
            var loc2;
            this._id = ++BaseTimer._baseID;
            this.delay = arg1;
            this.repeatCount = arg2;
            this._repeatCountCache = arg2;
            return;
        }

        public stop(): void
        {
            this._running = false;
            this.currentCount = 0;
            return;
        }

        public set isDelete(arg1: Boolean)
        {
            this._isDelete = arg1;
            return;
        }

        public get isDelete(): Boolean
        {
            return this._isDelete;
        }

        public get running(): Boolean
        {
            return this._running;
        }

        public get delay(): number
        {
            return this._delay;
        }

        public set delay(arg1: number)
        {
            this._delay = arg1;
            return;
        }

        public get repeatCount(): number
        {
            return this._repeatCount;
        }

        public set repeatCount(arg1: number)
        {
            this._repeatCount = arg1;
            return;
        }

        public reset(): void
        {
            this.repeatCount = this._repeatCountCache;
            this.currentCount = 0;
            this.isDelete = false;
            return;
        }

        public get isTimerQueue(): Boolean
        {
            return this._isTimerQueue;
        }

        public set isTimerQueue(arg1: Boolean)
        {
            this._isTimerQueue = arg1;
            return;
        }

        public dispose(arg1: Boolean=true): void
        {
            this._completeHandler = null;
            this._enterFrameHandler = null;
            this._isDelete = true;
            this._running = false;
            this._repeatCount = 0;
            this.isTimerQueue = false;
            this.currentCount = 0;
            return;
        }

        
        {
            BaseTimer._baseID = 0;
        }

        public set repeatCountCache(arg1: int)
        {
            this._repeatCountCache = arg1;
            return;
        }

        public get repeatCountCache(): int
        {
            return this._repeatCountCache;
        }

        public get type(): string
        {
            return "";
        }

        public get id(): int
        {
            return this._id;
        }

        public addListener(arg1: string, arg2: Function): void
        {
            if (arg1 != TimerType.COMPLETE) 
            {
                if (arg1 == TimerType.ENTERFRAME) 
                {
                    this._enterFrameHandler = arg2;
                }
            }
            else 
            {
                this._completeHandler = arg2;
            }
            return;
        }

        public renderer(arg1: int): void
        {
            var loc1;
            var loc2=((loc1 = this).currentCount + 1);
            loc1.currentCount = loc2;
            loc2 = ((loc1 = this).repeatCount - 1);
            loc1.repeatCount = loc2;
            if (typeof this._enterFrameHandler === "function") 
            {
                this._enterFrameHandler(this);
            }
            if (this.repeatCount <= 0) 
            {
                this._isDelete = true;
                this.isTimerQueue = false;
                if (typeof this._completeHandler === "function") 
                {
                    this._completeHandler(this);
                }
            }
            return;
        }

        public get interval(): int
        {
            return this._interval;
        }

        public set interval(arg1: int)
        {
            this._interval = arg1;
            return;
        }

        public start(): void
        {
            this._running = true;
            return;
        }

        private /* var */_isTimerQueue: Boolean=false;

        private /* var */_running: Boolean=false;

        private /* var */_id: int=0;

        private /* var */_isDelete: Boolean;

        private /* var */_delay: number;

        private /* var */_repeatCountCache: number;

        private /* var */_repeatCount: number;

        public /* var */currentCount: int;

        private /* var */_interval: int;

        private /* var */_enterFrameHandler: Function;

        private /* var */_completeHandler: Function;

        private static /* var */_baseID: int=0;
    }
